<?php

namespace app\models;

use Yii;
use app\models\BaseGoodsHy;

/**
 * This is the model class for table "{{%cart_item}}".
 *
 * @property integer $id
 * @property integer $cart_id
 * @property integer $hy_id
 * @property integer $sup_id
 * @property string $create_price
 * @property string $now_price
 * @property integer $quantuty
 * @property integer $create_at
 */
class CartItem extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%cart_item}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cart_id', 'hy_id', 'sup_id', 'create_price', 'now_price', 'quantity', 'created_at'], 'required'],
            [['cart_id', 'hy_id', 'sup_id', 'quantity', 'created_at'], 'integer'],
            [['create_price', 'now_price'], 'number']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cart_id' => '购物车id',
            'hy_id' => '货源id',
            'sup_id' => '供应商id',
            'create_price' => '加入购物车价格',
            'now_price' => '现在价格',
            'quantity' => '数量',
            'created_at' => '创建时间',
        ];
    }
    /**
     * author:sunjian
     * create_date： 2015年12月15日17:14:04
     * params $cart_id 购物车id
     * params $hy_id 货源id
     * return boolean
     * info 判断购物车中是否有该货源
     */
    
    static function checkCartItem($cart_id,$hy_id){
        return static::findOne(["cart_id"=>$cart_id,"hy_id"=>$hy_id]);
    }
    
    public function getGoodsHy(){
        return $this->hasOne(BaseGoodsHy::className(),['hy_id'=>'hy_id']);
    }
 
}
